﻿using System;
using System.Web;
using System.Data;

namespace msBsc.WebUi
{
    public partial class wfSoldOrderList : msBsc.Cls.BPDealer
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                loadlist("", "", "", "", "", "", "", "", "", "", ""); 
            }
        }

        private void ShowStatic()
        {
            using (msBsc.AppLogic.DataAlc.CBizShpCommercialTenantInfo odataobj = new AppLogic.DataAlc.CBizShpCommercialTenantInfo())
            {
                DataSet ds = odataobj.SelectSolpStatistic(msBsc.SvRef.UserInfo.OperDealerId.Split(',')[0]);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    this.ExecJScript("$('#emD2').html('" + ds.Tables[0].Rows[0]["WAIT_PAY_COUNT"].ToString() + "');");
                    this.ExecJScript("$('#emD3').html('" + ds.Tables[0].Rows[0]["WAIT_SHIPPING_COUNT"].ToString() + "');");
                    this.ExecJScript("$('#emD4').html('" + ds.Tables[0].Rows[0]["WAIT_RECEIPT_COUNT"].ToString() + "');");
                    this.ExecJScript("$('#emD5').html('" + ds.Tables[0].Rows[0]["WAIT_RETURN_COUNT"].ToString() + "');");
                    this.ExecJScript("$('#emD6').html('" + ds.Tables[0].Rows[0]["WAIT_REVIEW_COUNT"].ToString() + "');");
                }
            }
        }

        private void loadlist(string strGoodsNme, string strDealerNme, string strOrderNo, string strStartDt, string strEndDt, string strTradeSid, string strReviewSid, string strAfterSvcSid
            , string CurrPageNum, string strPageRowsCount, string strSort)
        {
            using (msBsc.AppLogic.DataAlc.CBizShpOrderForm odataobj = new AppLogic.DataAlc.CBizShpOrderForm())
            {
                DataSet ds = odataobj.SelectOrderForCustomFinder(msBsc.SvRef.UserInfo.OperDealerId.Split(',')[0],"", strGoodsNme, strDealerNme, strOrderNo, strStartDt, strEndDt, strTradeSid, strReviewSid, strAfterSvcSid);

                string strjsontem1 = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "ORDER_FORM_NO,INITIAL_DT,ORDER_FORM_ID,USER_NME,BUY_MEMO,COMM_TENANT_NME,COMM_TENANT_ID,TOTAL_AMT,DISCOUNT_AMT,PAYABLE_AMT,LOGISTICS_AMT,LOGISTICS_COMPANY_ID,WAYBILL_NUMBER,BUYER_RATE_SID,SELLER_RATE_SID,TRADE_STATUS_TXT,AFTER_SVC_STATUS_TXT"
                    , (CurrPageNum == string.Empty ? 1 : int.Parse(CurrPageNum))
                    , (strPageRowsCount == string.Empty ? 20 : int.Parse(strPageRowsCount))
                    , (strSort == string.Empty ? "INITIAL_DT DESC,ORDER_FORM_NO ASC,SEQ_NUM ASC" : strSort));
                this.ExecJScript(@" var data= " + strjsontem1 + @" ; 
                updateTableHtml( data);");
                ShowStatic();
            }
        }


        public override void DoAction()
        {
            if (this.strAction == "doFinderBoughtList")
            {
                loadlist(this.GetParamHtValue("GOODS_NME")
                    , this.GetParamHtValue("COMM_TENANT_NME")
                    , this.GetParamHtValue("ORDER_FORM_NO")
                    , this.GetParamHtValue("START_DT")
                    , this.GetParamHtValue("END_DT")
                    , this.GetParamHtValue("TRADE_STATUS_TXT")
                    , this.GetParamHtValue("REVIEW_STATUS_TXT")
                    , this.GetParamHtValue("AFTER_SVC_STATUS_TXT")
                    , this.GetParamHtValue("NEW_PAGE_NUM")
                    , this.GetParamHtValue("PAGE_ROW_COUNT")
                    , this.GetParamHtValue("PAGE_ROW_SORT"));
            }
            else if (this.strAction == "docancelorder")
            {
                System.Transactions.TransactionOptions transactionOption = new System.Transactions.TransactionOptions();
                transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
                transactionOption.Timeout = new TimeSpan(0, 10, 0);
                using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOption))
                {
                    using (msBsc.AppLogic.DataAlc.CBizShpOrderForm objorder = new AppLogic.DataAlc.CBizShpOrderForm())
                    {
                        objorder.ShopCancelOrder(this.GetParamHtValue("ID"));
                        this.ExecJScript("doToPageNm();");
                    }
                    ts.Complete();
                }
            }
            else if (this.strAction == "toreturncharge")
            {
                System.Transactions.TransactionOptions transactionOption = new System.Transactions.TransactionOptions();
                transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
                transactionOption.Timeout = new TimeSpan(0, 10, 0);
                using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOption))
                {
                    using (msBsc.AppLogic.DataAlc.CBizShpOrderForm objorder = new AppLogic.DataAlc.CBizShpOrderForm())
                    {
                        objorder.ShopReturnCharge(this.GetParamHtValue("ID"));
                        this.ExecJScript("doToPageNm();");
                    }
                    ts.Complete();
                }
            }
            else if (this.strAction == "dosetdiscountamt")
            {
                System.Transactions.TransactionOptions transactionOption = new System.Transactions.TransactionOptions();
                transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
                transactionOption.Timeout = new TimeSpan(0, 10, 0);
                using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOption))
                {
                    using (msBsc.AppLogic.DataAlc.CBizShpOrderForm objorder = new AppLogic.DataAlc.CBizShpOrderForm())
                    {
                        objorder.SetDiscountGoodsAmt(this.GetParamHtValue("ID"), this.GetParamHtValue("LID"), this.GetParamHtValue("CHARGE_AMT"));
                        this.ExecJScript("doToPageNm();");
                    }
                    ts.Complete();
                }
            }
            else if (this.strAction == "doresetlogisticamt")
            {
                System.Transactions.TransactionOptions transactionOption = new System.Transactions.TransactionOptions();
                transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
                transactionOption.Timeout = new TimeSpan(0, 10, 0);
                using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOption))
                {
                    using (msBsc.AppLogic.DataAlc.CBizShpOrderForm objorder = new AppLogic.DataAlc.CBizShpOrderForm())
                    {
                        objorder.SetLogisticsAmt(this.GetParamHtValue("ID"), this.GetParamHtValue("CHARGE_AMT"));
                        this.ExecJScript("doToPageNm();");
                    }
                    ts.Complete();
                }
            }
            else if (this.strAction == "dodeleteorder")
            {
                System.Transactions.TransactionOptions transactionOption = new System.Transactions.TransactionOptions();
                transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
                transactionOption.Timeout = new TimeSpan(0, 10, 0);
                using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOption))
                {
                    using (msBsc.AppLogic.DataAlc.CBizShpOrderForm objorder = new AppLogic.DataAlc.CBizShpOrderForm())
                    {
                        objorder.ShopDeleteOrder(this.GetParamHtValue("ID"));
                        this.ExecJScript("doToPageNm();");
                    }
                    ts.Complete();
                }
            }
        }
    }
}